package com.yanqu.road.server.manger.activity.curio.condition;

import com.yanqu.road.entity.config.patrons.PatronsInfo;
import com.yanqu.road.entity.config.promotion.PromotionInfo;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.manger.config.PromotionMgr;

import java.util.List;
import java.util.Map;

/**
 * 结识无双门客
 */
public class GetPeerlessPatronsNumCondition extends BaseCurioSpecialCondition {

    public GetPeerlessPatronsNumCondition(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean isCompleted(List<Integer> params) {
        int conditionNum = params.get(0);
        return getConditionValue(params) > conditionNum;
    }

    @Override
    public long getConditionValue(List<Integer> params) {
        int num = 0;
        Map<Integer, UserPatrons> patronsMap = player.getModule(PatronsModule.class).getUserPatronsMap();
        for (Map.Entry<Integer, UserPatrons> entry : patronsMap.entrySet()) {
            UserPatrons patrons = entry.getValue();
            if(patrons.getShowPromotionId() > 0){
                PromotionInfo promotionInfo = PromotionMgr.getPromotionInfoById(patrons.getShowPromotionId());
                if(promotionInfo != null && promotionInfo.getQuality() == 5){
                    num++;
                }
            }else {
                PatronsInfo patronsInfo = PatronsMgr.getPatronsInfo(entry.getKey());
                if(patronsInfo == null){
                    continue;
                }
                if(patronsInfo.getQuality() == 5){
                    num++;
                }
            }
        }
        return num;
    }
}
